package com.example.bobo.yuejian322.Fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import com.example.bobo.yuejian322.Fragment.zhuyeFragment.ActivityFragment;
import com.example.bobo.yuejian322.Fragment.zhuyeFragment.MasterFragment;
import com.example.bobo.yuejian322.Fragment.zhuyeFragment.PlayFragment;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseFragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class ZhuyeFragment extends BaseFragment {
    private RadioGroup radioGroup;

    private ActivityFragment activityFragment;
    private MasterFragment masterFragment;
    private PlayFragment playFragment;

    private FragmentManager manager;
    private FragmentTransaction transaction;

    public ZhuyeFragment() {
        // Required empty public constructor
    }

    private void replace(Fragment fragment) {
        transaction = manager.beginTransaction();
        transaction.replace(R.id.zhuye_framelayout, fragment);
        transaction.commit();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup_zhuye);
        manager = getChildFragmentManager();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radio_activity:
                        activityFragment = new ActivityFragment();
                        replace(activityFragment);
                        break;

                    case R.id.radio_master:

                        masterFragment = new MasterFragment();
                        replace(masterFragment);

                        break;

                    case R.id.radio_play:
                        playFragment = new PlayFragment();
                        replace(playFragment);

                        break;
                }

            }
        });

        radioGroup.check(R.id.radio_activity);



    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_zhuye, container, false);
    }

}
